package com.ap.core.validation.message.rules;

import com.ap.core.cxf.jaxb.managepayment.ConfirmPaymentMsgType;
import com.ap.core.dao.FinancialInstitutionDao;
import com.ap.core.domain.FinancialInstitution;
import com.ap.core.message.info.RequestMessageInfo;
import com.ap.core.message.managepayment.info.ConfirmPaymentRequestMessageInfo;
import com.ap.core.validation.message.info.MessageValidationInfo;
import com.ap.core.validation.message.info.RTPOriginalInfo;
import com.ap.core.validation.rules.AbstractValidationRule;

/**
 * User: Ranjit.Singh
 * Check if provided FI ID is valid
 */
public class ValidFIIdRuleConfirmPayment extends AbstractValidationRule<MessageValidationInfo<RequestMessageInfo<ConfirmPaymentMsgType>, RTPOriginalInfo>> {

    private FinancialInstitutionDao financialInstitutionDao;
    private FinancialInstitution financialInstitution;
    
    @Override
    public boolean validate(MessageValidationInfo<RequestMessageInfo<ConfirmPaymentMsgType>, RTPOriginalInfo> infoObject) {
    	if(infoObject.getBoundObject() instanceof ConfirmPaymentRequestMessageInfo) {
    		financialInstitution = financialInstitutionDao.getFIByIdentification(((ConfirmPaymentRequestMessageInfo) infoObject.getBoundObject()).getConsumerAcct().getFIId());
    	} 
        return null != financialInstitution;
    }

    public void setFinancialInstitutionDao(FinancialInstitutionDao financialInstitutionDao) {
        this.financialInstitutionDao = financialInstitutionDao;
    }
}
